#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <assert.h>

int main()
{
	int serv_sock,clnt_sock;
	
	struct sockaddr_in serv_addr;
	struct sockaddr_in clnt_addr;
	
	socklen_t clnt_addr_size=sizeof(clnt_addr);
	
	memset(&serv_addr,0,sizeof(serv_addr));
	memset(&clnt_addr,0,sizeof(clnt_addr));
	
	char *message="hello world";
	
	serv_addr.sin_family=AF_INET;
	serv_addr.sin_addr.s_addr=htonl(INADDR_ANY);
	serv_addr.sin_port=htons(atoi("1024"));
	
	serv_sock=socket(AF_INET,SOCK_STREAM,0);

	int bindre=bind(serv_sock,(struct sockaddr*)&serv_addr,sizeof(serv_addr));
	if(bindre!=0)
	{
		perror("bind:");
	}
	
	int listenre=listen(serv_sock,5);
	if(listenre!=0)
	{
		perror("listen");
	}
	
		socklen_t clnt_len=sizeof(clnt_addr);

		clnt_sock=accept(serv_sock,(struct sockaddr*)&clnt_addr,
		&clnt_len);
		if(clnt_sock==-1)
		{
			perror("accept");
		}

		char buffer[100]={0};
		read(clnt_sock,buffer,100);
		printf("server:%s\n",buffer);

		printf("clinet connet ip %s.\n",
			inet_ntoa(clnt_addr.sin_addr));
		
		
	return 0;
}